package com.tjsinfo.tjsoa.worklog.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.tjsinfo.tjsoa.worklog.vo.WorkLogExamine;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;


public class WorkLogExamineDao extends HibernateBaseDao implements IWorkLogExamineDao{

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worklog.hibernatedao.IWorkLogExamineDao#selectWorkLog(java.lang.Integer, java.lang.Integer)
	 */
	public WorkLogExamine selectWorkLog(final Integer userid,final  String jihua) {
		// TODO Auto-generated method stub
		return (WorkLogExamine)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{

					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						// TODO Auto-generated method stub
						Query query =	arg0.createQuery("from  WorkLogExamine work where work.workLogMain.id = ? and work.tjsUser.id =?");
						query.setParameter(0, jihua);
						query.setParameter(1, userid);
						return query.uniqueResult();
					}
					
				});
	}

	public List selectSuddenlyWorkLog(final Integer userid, final Integer start) {
		

			return (List)this.getHibernateTemplate().execute(
					new HibernateCallback()
					{

						public Object doInHibernate(Session arg0)
								throws HibernateException, SQLException {
							// TODO Auto-generated method stub
							Query query =	arg0.createQuery("from WorkLogExamine work inner join fetch  work.workLogMain inner join fetch work.workLogMain.tjsUser where work.tjsUser.id = ? and work.examineState = ?");
							query.setParameter(0, userid);
							query.setParameter(1, start);
							return query.list();
						}
						
					});
		}
	
	
}
